<template>
  <main class="main">
    <div class="top">
      <div class="left">
        <img src="" alt="" />
        <span class="title">分拣系统</span>
      </div>
      <el-popover placement="bottom" title="" :width="150" trigger="click">
        <template #reference>
          <div class="right">
            <span>{{ dayjs().format('YYYY-MM-DD') }}</span>
            <img src="../assets/image/headImg.png" alt="" />
            <span>{{ userName }}</span>
          </div>
        </template>
        <el-button style="width: 100%" @click="layout">退出登录</el-button>
      </el-popover>
    </div>
    <div class="second">
      <div class="left">
        <el-Space v-if="currentRoute === '/'">
          <el-select v-model="headValue" placeholder="请选择" style="margin-right: 30px">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
          配送日期：<el-date-picker
            v-model="date"
            type="date"
            placeholder="请选择日期"
            @change="dateChange"
          />
        </el-Space>
        <el-Space v-else class="leftHome">
          <div class="flexAliCenter" @click="goBack">
            <el-icon class="leftIcon"><ArrowLeft /></el-icon> 返回
          </div>
          <span style="margin: 0 10px">|</span>
          <div class="flexAliCenter" @click="goPage('/')">
            <el-icon class="home"><HomeFilled /></el-icon>
            首页
          </div>
          <div class="dateText">{{ dayjs(date).format('MM月DD日') }}配送的订单</div>
        </el-Space>
      </div>
      <div class="right" @click="goPage('setting')">
        <span>设置</span> <el-icon><ArrowDown /></el-icon>
      </div>
    </div>
  </main>
</template>

<script lang="ts" setup>
import router from '../router'
import { ref, watch } from 'vue'
import { dayjs } from 'element-plus'
const headValue = ref('1')
const date = ref(sessionStorage.getItem('date') || new Date())
const userName = JSON.parse(sessionStorage.getItem('userInfo') as string)[0].FNumber
sessionStorage.setItem(
  'date',
  dayjs(date.value).format('YYYY-MM-DD') || dayjs(new Date()).format('YYYY-MM-DD')
)
const options = [
  {
    value: '1',
    label: '按收货时间'
  }
]
const currentRoute = ref('')
const goPage = (path: string) => {
  router.push(path)
}
const goBack = () => {
  router.back()
}
watch(
  () => router.currentRoute.value,
  (toPath) => {
    currentRoute.value = toPath.path
  },
  { immediate: true, deep: true }
)
const dateChange = (res: string) => {
  sessionStorage.setItem('date', res)
}
const layout = () => {
  sessionStorage.removeItem('token')
  router.push('login')
}
</script>

<style scoped lang="less">
.main {
  background: var(--vt-c-white);
  padding: 10px 26px;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      display: flex;
      align-items: center;
      img {
        width: 36px;
        height: 36px;
      }
      .title {
        color: var(--vt-c-black-soft);
        margin-left: 36px;
        font-size: 20px;
        font-family: Alibaba-PuHuiTi, Alibaba-PuHuiTi;
        font-weight: bold;
        line-height: 27px;
      }
    }
    .right {
      display: flex;
      align-items: center;
      cursor: pointer;
      span {
        font-size: 15px;
        font-family:
          PingFangSC,
          PingFang SC;
        font-weight: 500;
        color: #a3a9cd;
        line-height: 21px;
      }
      img {
        width: 26px;
        height: 26px;
        margin-left: 20px;
        margin-right: 5px;
      }
    }
  }
  .second {
    margin-top: 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .right {
      display: flex;
      cursor: pointer;
      align-items: center;
      span {
        margin-right: 5px;
      }
    }
  }
}
.leftHome {
  display: flex;
  align-items: center;
  font-size: 18px;
  color: #8994b6;
  cursor: pointer;
  .leftIcon {
    margin-top: 4px;
  }
  .home {
    font-size: 26px;
    margin-right: 7px;
    margin-top: -2px;
  }
  .dateText {
    font-size: 18px;
    color: #333333;
    line-height: 23px;
    margin-left: 20px;
  }
}
</style>
